'use strict';

import * as actions from '../../actions/zhekou1_all_in_list';

// 对页面prop 数据进行管理
const initialState = {
  creating: false,
  error:false,
  loginError:false,
  message:"",
  curActive:false
};
const defaultAction = {
  type: 'doNothing'
};

export default function index(state = initialState, action = defaultAction ) {

  switch (action.type) {
    case actions.LOAD_START:
      return Object.assign({}, state, {
        creating:true,
        error:false,
        loginError:false
      });
	  break;
    case actions.LOAD_ERR:
      return Object.assign({}, state, {
        creating:false,
		error:true,
		loginError:action.loginFalse,
		message:action.message
      });
	  break;
    case actions.GET_LIST_DONE:
      return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false,
		data:action.data,
        activityId:action.activityId
      });
	  break;
    case actions.GET_DETAIL_DONE:
	  state.data.item_promotion_list.item_promotion.map((act,key)=>{
		if(act.activity_id==action.data.item_promotion.activity_id){
			state.data.item_promotion_list.item_promotion[key]=action.data.item_promotion;
		}
	  });
      return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false,
		curActive:action.curActive,
		showEditDialog:true
      });
	  break;
    case actions.EDIT_DIALOG:
      return Object.assign({}, state, {
		curActive:action.active,
        showEditDialog:action.show
      });
	  break;
    case actions.SET_CUR_PARAM:
	  const curActive = (Object.assign({}, state.curActive, action.param));
      return Object.assign({}, state, {curActive});
	  break;
    case actions.CLOSE_DIALOG:
      return Object.assign({}, state, {
		error:action.visible,
        loginError:false
      });
	  break;
    case actions.EDIT_ACTIVE:
	  state.data.item_promotion_list.item_promotion.map((act,key)=>{
		if(act.activity_id==action.data.activity_id){
			state.data.item_promotion_list.item_promotion[key]=action.data;
		}
	  });
      return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false
	  });
	  break;
    case actions.REMOVE_ACTIVE:
	  state.data.item_promotion_list.item_promotion.map((act,key)=>{
		  if(act.activity_id==action.activity_id){
				state.data.item_promotion_list.item_promotion.splice(key,1);
			}
	  });
      return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false
	  });
	  break;
    default:
      return state;
  }
}

